package com.base.service.web.controller;

import com.base.core.utils.R;
import com.base.storage.StorageFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/storage")
@RestController
@CrossOrigin
public class StorageController {

    @Autowired
    private StorageFactory storageFactory;

    /**
     * 上传MultipartFile类型的文件
     * @param file MultipartFile类型的文件
     * @return
     */
    @PostMapping("/file")
    public R uploadFile(MultipartFile file) throws Exception {
        String filePath = storageFactory.getStorage().upload(file);
        return R.success(filePath);
    }

    @PostMapping("/base64")
    public R uploadBase64Data(@RequestBody String base64) throws Exception {
        String filePath = storageFactory.getStorage().upload(base64);
        return R.success(filePath);
    }

}
